Barcode detection device with width calibration

ABSTRACT

There is provided a barcode detection device including an image sensor and a processor. The image sensor captures an image frame of a barcode. The processor calculates a gradient vector of bars of the barcode in the image frame for determining a rotation angle of the image sensor. The rotation angle is used to calibrate a detected bar width.

RELATED APPLICATIONS

The present application is a divisional application of U.S. patentapplication Ser. No. 17/333,197 filed on May 28, 2021, the disclosure ofwhich is hereby incorporated by reference herein in its entirety.

BACKGROUND 1. Field of the Disclosure

This disclosure generally relates to an optical barcode detection deviceand, more particularly, to a barcode detection device that calibrates arotation angle of the barcode detection device.

2. Description of the Related Art

It is known that a barcode can be used to indicate the position or theobject on which the barcode is arranged. Using different combinations ofwidths or colors of bars to form different barcodes, it is able todistinguish different positions or different objects by a sensor thatmoves over the different barcodes.

However, when the sensor detects one barcode with a rotation angle, thedetected width of bars of the one barcode upon which the sensor locatescan be changed such that an incorrect width is detected. If thisrotation angle is not calibrated, the operations based on the rotationangle may cause mistakes.

Accordingly, the present disclosure further provides an optical barcodedetection device that determines a rotation angle of the barcodedetection device with respect to a barcode under detection beforeoutputting a detection result.

SUMMARY

The present disclosure provides an optical barcode detection device thatcalculates a gradient vector of a barcode for determining a rotationangle of the barcode detection device with respect to the barcode.

The present disclosure further provides an optical barcode detectiondevice that calculates a gradient vector of a barcode for determining ascan direction and an operation state of the barcode detection device.

The present disclosure further provides an optical barcode detectiondevice that directly determines a scan direction of a sensor byidentifying which of four predetermined angle regions that a calculatedgradient vector of a barcode locates.

The present disclosure provides a barcode detection device including animage sensor and a processor. The image sensor is configured to capturean image frame of a barcode, wherein the image frame has a size of N×Npixels, and the barcode has separately arranged multiple bars. Theprocessor is coupled to the image sensor, and configured to calculate anangle difference between a gradient direction in the captured imageframe and a predetermined direction of the captured image frame,calculate a scanned width of the multiple bars, and calibrate thescanned width using the angle difference to obtain a calibrated width.

The present disclosure further provides a barcode detection deviceincluding an image sensor and a processor The image sensor is configuredto capture an image frame of a barcode, wherein the image frame has asize of N×N pixels, and the barcode has separately arranged multiplebars. The processor is coupled to the image sensor, and configured tocalculate a gradient direction in the captured image frame, select adirection from four predetermined directions, which is closest to thegradient direction, of the captured image frame, and calibrate a scannedwidth of the multiple bars using an angle difference between thegradient direction and the selected direction.

BRIEF DESCRIPTION OF THE DRAWINGS

Other objects, advantages, and novel features of the present disclosurewill become more apparent from the following detailed description whentaken in conjunction with the accompanying drawings.

FIG. 1 is a schematic block diagram of a barcode detection deviceaccording to one embodiment of the present disclosure.

FIG. 2 is a schematic diagram of a scan direction and a gradient vectorof a convolution region in an image frame captured by an image sensor ofa barcode detection device according to one embodiment of the presentdisclosure.

FIG. 3 is a schematic diagram of a line buffer for storing gradientvectors calculated by a barcode detection device according to oneembodiment of the present disclosure.

FIG. 4 is a schematic diagram of calculating a scanned width by abarcode detection device according to one embodiment of the presentdisclosure.

FIG. 5 is a schematic diagram of selecting a scan direction from fourdirections according to a gradient vector calculated by a barcodedetection device according to one embodiment of the present disclosure.

DETAILED DESCRIPTION OF THE EMBODIMENT

It should be noted that, wherever possible, the same reference numberswill be used throughout the drawings to refer to the same or like parts.

The barcode detection device of the present disclosure is adapted tocalibrate a rotation angle (as well as to identify a scanned width, ifneeded) of bars of a barcode and determine a scan direction beforerecognizing the barcode. In this way, the barcode detection device ofthe present disclosure can identify whether it is lifted up or stillbeing operated during the recognizing to avoid error recognition of thebarcode. Furthermore, the barcode detection device of the presentdisclosure only needs to scan once along the determined scan directionso as to reduce computation loading, which is generally ¼ of thecomputation loading of conventional detection devices that determine ascan direction after scanning four directions.

Please referring to FIG. 1 , it is a schematic block diagram of abarcode detection device 100 according to one embodiment of the presentdisclosure. The barcode detection device 100 includes an image sensor11, a processor 12, a line buffer 13 and an output interface 14. Inanother aspect, the line buffer 13 is arranged inside the processor 12.In another aspect, the line buffer 13 is replaced by a frame buffer. Thebarcode detection device 100 is arranged on an object, e.g., a characterfigure, and is used to detect different barcodes via one surface of theobject.

The output interface 14 is a wireless interface, e.g., a Bluetoothinterface, but not limited to. The output interface 14 is used tocommunicate with an external host, e.g., a game host, a cellphone or thelike. In another aspect, the barcode detection device 100 does notinclude the output interface 14, and the processor 12 controls theobject on which the barcode detection device 100 is embedded.

The image sensor 11 is a CMOS image sensor, a CCD image sensor or thelike, and is used to capture an image frame of a barcode 90, which hasseparately arranged multiple bars. The multiple bars have differentcolors or different reflectivity, e.g., represented by different filledtypes of lines in FIG. 1 , to form a specific code for indicating aposition or an object.

For example, FIG. 2 shows an image frame IF captured by the image sensor11 of the barcode detection device 100. The image frame IF has a size ofN×N pixels, e.g., shown as 7×7 pixels, but not limited to. Forillustration purposes, FIG. 2 only shows an edge of a bar of the barcode90 without showing images of other bars. In actual operation, the imageframe IF preferably contains images of multiple bars of the barcode 90.FIG. 1 shows that a field of view θf of the image sensor 11 covers onebarcode 90.

The processor 12 is a microcontroller unit (MCU) or an applicationspecific integrated circuit (ASIC), and performs calculations andoperations thereof (described below) using hardware and/or firmware. Theprocessor 12 is coupled to the image sensor 11 to receive the capturedimage frame IF therefrom, and determines a scan direction Ascan (asshown in FIG. 2 ) of scanning the multiple bars of the barcode 90 anddetermines an arrangement angle Abar (as shown in FIGS. 1 and 2 ) of themultiple bars of the barcode 90 to accordingly calibrate a rotationangle θ, described below. More specifically, if the scan direction Ascandoes not match the arrangement angle Abar (i.e. having an included angleθ therebetween), it means that the rotation angle θ is not calibratedand the scanned width of the bars of the barcode 90 is not correct. Andwhen the rotation angle θ is calibrated then a correct scanned width ofthe bars of the barcode 90 could be obtained.

In the present disclosure, the processor 12 calculates a convolution ofthe image frame IF respectively with a first gradient matrix M_(X) and asecond gradient matrix M_(Y) to obtain (N−1)×(N−1) gradient vectors, forexample,

$M_{X} = {{\begin{bmatrix}{- 1} & 0 & 1 \\{- 2} & 0 & 2 \\{- 1} & 0 & 1\end{bmatrix}{and}M_{Y}} = {\begin{bmatrix}{- 1} & {- 2} & {- 1} \\0 & 0 & 0 \\1 & 2 & 1\end{bmatrix}.}}$

As shown above, the first gradient matrix M_(X) is used to subtract aleft column from a right column, separated from the left column by onepixel column, of the image frame IF to obtain an X-gradient component ofthe gradient vector associated with a convolution region CR (as shown inFIG. 2 ) of the image frame IF; and the second gradient matrix M_(Y) isused to subtract an upper row from a lower row, separated from the upperrow by one pixel row, of the image frame IF to obtain a Y-gradientcomponent of the gradient vector associated with the convolution regionCR (as shown in FIG. 2 ) of the image frame IF.

In another aspect, the first gradient matrix is used to subtract a rightcolumn from a left column, separated from the right column by one pixelcolumn, of the image frame IF to obtain an X-gradient component of thegradient vector associated with a convolution region CR of the imageframe IF; and the second gradient matrix M_(Y) is used to subtract anlower row from a upper row, separated from the lower row by one pixelrow, of the image frame IF to obtain a Y-gradient component of thegradient vector associated with the convolution region CR of the imageframe IF. That is, in M_(X), the first column contains positivecomponents, and the third column contains negative components; and inM_(Y), the first row contains positive components, and the third rowcontains negative components. It is appreciated that sizes of M_(X) andM_(Y) are not limited to 3×3.

Referring to FIG. 2 again, the first gradient matrix M_(X) and thesecond gradient matrix M_(Y) are respectively convoluted with aconvolution region CR which moves or scans from the top left corner ofthe image frame IF to the lower right corner of the image frame IF suchthat (N−1)×(N−1) times of convolution between the first gradient matrixM_(X) and the convolution region CR are calculated by the processor 12,and (N−1)×(N−1) times of convolution between the second gradient matrixM_(Y) and the convolution region CR are calculated.

The convolution between the first gradient matrix M_(X) and oneconvolution region CR obtains one X-component of a gradient vector,shown as G_(X22), G_(X23) . . . G_(XN-1N-1) in FIG. 3 . The convolutionbetween the second gradient matrix M_(Y) and one convolution region CRobtains one Y-component of a gradient vector, shown as G_(Y22), G_(Y23). . . G_(YN-1N-1) in FIG. 3 .

As shown in FIG. 3 , the line buffer 13 is used to store the calculatedgradient vectors. For example, when a center C of the convolution regionCR is at (2,2) of the image frame IF, the convolution between theconvolution region CR and the first gradient matrix M_(X) obtains anX-component G_(X22); and the convolution between the convolution regionCR and the second gradient matrix M_(Y) obtains a Y-component G_(Y22),shown as a gradient vector (G_(X22), G_(Y22)). Then, the center C of theconvolution region CR moves right by one pixel to (2,3), and theconvolution between the convolution region CR and the first gradientmatrix M_(X) as well as the second gradient matrix M_(Y) obtains agradient vector (G_(X23), G_(Y23)). The convolution region CR is thensequentially moved toward the right-lower corner to totally obtain anumber of (N−1)×(N−1) gradient vectors sequentially stored in the linebuffer 13. In the present disclosure, the convolutions when the center Cis located at edge pixels are not calculated.

It is appreciated that if the first gradient matrix M_(X) and a secondgradient matrix M_(Y) have a larger size, e.g., 4×4, a number of timesfor calculating the convolution between the convolution region CR (alsohaving 4×4 pixels) and the first gradient matrix M_(X) as well as thesecond gradient matrix M_(Y) is decreased, e.g., obtaining (N−2)×(N−2)gradient vectors.

Then, the processor 12 calculates an average gradient vector (G_(Xave),G_(Yave)) of the (N−1)×(N−1) gradient vectors associated with(N−1)×(N−1) convolution regions CR of the image frame IF, wherein theaverage gradient vector also has an X-component G_(Xave) and aY-component G_(Yave). Referring to FIG. 3 ,

G _(Xave)=(G _(X22) +G _(X23) + . . . +G _(X2N-1) +G _(X32) +G _(X33) +. . . +G _(X3N-1) + . . . +G _(XN-1N-1))/(N−1)²

G _(Yave)=(G _(Y22) +G _(Y23) + . . . +G _(Y2N-1) +G _(Y32) +G _(Y33) +. . . +G _(Y3N-1) + . . . +G _(YN-1N-1))/(N−1)²

However, in calculating the average gradient vector (G_(Xave),G_(Yave)),the (N−1)×(N−1) gradient vectors are not always directed to a samedirection. Mostly, about a half of gradient vectors among the(N−1)×(N−1) gradient vectors are positive and another half of gradientvectors among the (N−1)×(N−1) gradient vectors are negative (i.e.directed in opposite directions); and thus the average gradient vector(G_(Xave),G_(Yave)) are close to (0,0) without considering noises.

In one aspect, the negative gradient vector herein is referred to agradient vector that has a negative value of arrangement angle Abar(e.g., calculated by arctan(G_(Y22)/G_(X22)), arctan(G_(Y23)/G_(X23)), .. . , arctan(G_(YN-1N-1)/G_(XN-1N-1))); and a positive gradient vectorherein is referred to a gradient vector that has a positive value ofarrangement angle Abar.

In a word, to solve the cancellation issue (e.g., summation of gradientvectors having opposite directions becoming 0) in calculating theaverage gradient vector (G_(Xave),G_(Yave)), gradient vectors havingopposite directions are firstly changed to the same direction beforecalculating the average gradient vector (G_(Xave),G_(Yave)).

In one aspect, it is possible to calculate the inner product of twogradient vectors among the (N−1)×(N−1) gradient vectors to determinewhether the two gradient vectors are in the same direction or not. Ifthe inner product of two gradient vectors is larger than 0, then the twogradient vectors are in the same direction. If the inner product of twogradient vectors is not larger than 0, it is known that one of the twogradient vectors directs to a first direction and the other one of thetwo gradient vectors directs to a second direction, e.g., opposite tothe first direction. By adding a minus sign to the other one gradientvector directing to the second direction, a direction of the other onegradient vector is changed to direct to the first direction.

In another aspect, it is possible to calculate the absolute differencebetween two gradient vectors among the (N−1)×(N−1) gradient vectors todetermine whether the two gradient vectors are in the same direction ornot. If the angle difference of two gradient vectors is smaller than 90degrees, the two gradient vectors are in the same direction. If theangle difference of two gradient vectors is not smaller than 90 degrees,it is known that one of the two gradient vectors directs to a firstdirection and the other one of the two gradient vectors directs to asecond direction, e.g., opposite to the first direction. By adding aminus sign to the other one gradient vector directing to the seconddirection, a direction of the other one gradient vector is changed todirect to the first direction.

Then, the average gradient vector (G_(Xave),G_(Yave)) is calculated byaveraging (N−1)×(N−1) gradient vectors directing to the first direction(including direction changed and non-changed gradient vectors); or, byaveraging the gradient vectors among the (N−1)×(N−1) gradient vectorsdirecting only to the first direction or directing only to the seconddirection and ignoring gradient vectors not directing to the samedirection.

In one aspect, the arrangement angle Abar (also called a gradientdirection of multiple bars herein) is calculated usingarctan(G_(Yave)/G_(Xave)) by the processor 12. As the scan directionAscan in scanning the multiple bars of the barcode 90 in the image frameIF is only set in four directions, including a longitudinal direction Y,a transverse direction X, a 45-degree tilt direction (a diagonal line)and a 135-degree tilt direction (another diagonal line) of the imageframe IF, the processor 12 further calculates an angle difference θbetween the arrangement angle Abar and a predetermined directionselected from the longitudinal direction Y, the transverse direction X,the 45-degree tilt direction and the 135-degree tilt direction of theimage frame IF.

For example, after the arrangement angle Abar is obtained, the processor12 selects one of the longitudinal direction Y, the transverse directionX, the 45-degree tilt direction and the 135-degree tilt directionclosest to the arrangement angle Abar of the average gradient vector(G_(Yave),G_(Xave)), e.g., FIG. 2 showing 135-degree tilt directionbeing selected. The processor 12 then calculates a difference betweenthe arrangement angle Abar of the average gradient vector(G_(Yave),G_(Xave)) and a selected direction, e.g., 135-degree diagonaldirection in FIG. 2 , as the angle difference θ.

The processor 12 also calculates a scanned width W of the multiple bars.Referring to FIG. 4 , in one aspect, the processor 12 calculates thescanned width W using two adjacent bars in the image frame IF. Forexample, the processor 12 uses the equation[(stop2−stop1)+(start2−start1)]/4 to calculate the scanned width W,wherein the stop2, stop1, start2 and start1 are pixel positions. Inanother aspect, the processor 12 may use other method to calculate thescanned width W. For example, W=(stop1−start1) or W=(stop2−start2). Ifthere is an angle difference θ between Abar and Ascan, the scanned widthW is not taken as a real width of the multiple bars of the barcode 90.

After the scanned width W is obtained, the processor 12 calibrates thescanned width W using the angle difference θ to obtain a calibratedwidth, e.g., Wcal=W/sec0.

As mentioned above, the calibrated width Wcal indicates the real widthof the bars, the spaces or a bar pitch of the barcode 90. In one aspect,the processor 12 compares the calibrated width Wcal with a predeterminedthreshold to determine whether the barcode detection device 100 islifted by a user or not. For example, if the calibrated width Wcal issmaller than the predetermined threshold, the barcode detection device100 is determined to be lifted. For example, if the barcode detectiondevice 100 is determined to be lifted, the processor 12 does notrecognize the current barcode or does not output the recognized barcodefrom the output interface 14 or does not perform the predeterminedcontrol. In another aspect, the calibrated width Wcal is used toindicate a lifted height. For example, the calibrated width Wcal iscompared with multiple thresholds, each interval between two thresholdsindicating one height, to determine a height of the barcode detectiondevice 100 with respect to the barcode 90.

In another aspect, the processor 12 further identifies a variation ofthe average gradient vector (G_(Yave),G_(Xave)) or the arrangement angleAbar to determine whether the barcode detection device 100 is steady ornot. For example, if the average gradient vector (G_(Yave),G_(Xave)) orthe arrangement angle Abar changes between adjacent or successive imageframes, it means that the barcode detection device 100 is still beingoperated by a user and thus the processor 12 does not recognize thecurrent barcode or does not output the recognized result from the outputinterface 14 or does not perform the predetermined control.

As mentioned above, the average gradient vector (G_(Yave),G_(Xave)) isused to calculate the arrangement direction Abar of the multiple bars ofthe barcode 90, e.g., calculating arctan(G_(Yave)/G_(Xave)), and thenused to determine a scan direction of scanning the multiple bars closestto the arrangement direction Abar. However, the computation ofarctan(G_(Yave)/G_(Xave)) is difficult to be implemented using thehardware. In some scenarios that a width deviation of the multiple barsof the barcode 90 caused by the angle difference θ is tolerable orignorable, the processor 12 uses another way to determine a scandirection of scanning the multiple bars of the barcode 90 according tothe X-component G_(Xave) and the Y-component G_(Yave) of the averagegradient vector (G_(Yave),G_(xave)).

For example, when 53×|G_(Xave)|>128×|G_(Yave)| (i.e. within a transverseregion as shown FIG. 5 ), the scan direction Ascan is determined as atransverse direction X of the image frame IF; when53×|G_(Yave)>128×|G_(Xave)| (i.e. within a longitudinal region as shownFIG. 5 ), the scan direction Ascan is determined as a longitudinaldirection Y of the image frame IF; when G_(Xave)×G_(Yave)>0 (i.e. withina 45-degree region as shown FIG. 5 ), the scan direction Ascan isdetermined as a 45-degree tilt direction of the image frame IF, andotherwise (i.e. within a 135-degree region as shown FIG. 5 ), the scandirection Ascan is determined as a 135-degree tilt direction of theimage frame IF. This computation is directly embedded in the hardware ofthe processor 12. FIG. 5 shows that the arrangement direction Abar iswithin the 45-degree region, and the scan direction is determined along45-degree tilt direction. It is also possible to obtain an angledifference θ using FIG. 5 .

It should be mentioned that although the gradient vector mentioned inthe above embodiments is a gradient vector of multiple bars, thegradient vector is also a gradient vector of spaces between the multiplebars since each space is arranged between two adjacent bars.

As mentioned above, if the sensor is not steady during recognizing abarcode, an incorrect barcode may be recognized. Accordingly, thepresent disclosure further provides an optical barcode detection device(e.g., FIG. 1 ) that calculates an arrangement angle of multiple bars ofthe barcode under detection at first, and the calculated arrangementangle is then used to determine a scan direction of scanning the barcodeand to calibrate a scanned width of the multiple bars. The calibratedwidth is used to determine a height of the barcode detection device withrespect to the barcode.

Although the disclosure has been explained in relation to its preferredembodiment, it is not used to limit the disclosure. It is to beunderstood that many other possible modifications and variations can bemade by those skilled in the art without departing from the spirit andscope of the disclosure as hereinafter claimed.

What is claimed is:
 1. A barcode detection device, comprising: an imagesensor, configured to capture an image frame of a barcode, wherein theimage frame has a size of N×N pixels, and the barcode has separatelyarranged multiple bars; and a processor, coupled to the image sensor,and configured to calculate an angle difference between a gradientdirection in the captured image frame and a predetermined direction ofthe captured image frame, calculate a scanned width of the multiplebars, and calibrate the scanned width using the angle difference toobtain a calibrated width.
 2. The barcode detection device as claimed inclaim 1, wherein the processor is configured to calculate an averagegradient vector of (N−1)×(N−1) gradient vectors of (N−1)×(N−1)convolution regions of the image frame as the gradient direction of themultiple bars, wherein the predetermined direction comprises alongitudinal direction, a transverse direction, a 45-degree tiltdirection and a 135-degree tilt direction of the image frame.
 3. Thebarcode detection device as claimed in claim 1, wherein the processor isfurther configured to compare the calibrated width with a threshold todetermine whether the barcode detection device is lifted or not.
 4. Thebarcode detection device as claimed in claim 2, wherein the processor isconfigured to calculate the gradient direction of the average gradientvector by calculating convolutions of the (N−1)×(N−1) convolutionregions of the image frame respectively with a first gradient matrix anda second gradient matrix to obtain the (N−1)×(N−1) gradient vectors,averaging the (N−1)×(N−1) gradient vectors to obtain the averagegradient vector, which has an X-component and a Y-component, andcalculating arctan(Y-component/X-component) as the gradient direction ofthe average gradient vector.
 5. The barcode detection device as claimedin claim 1, wherein the processor is configured to calculate the scannedwidth using two adjacent bars in the image frame.
 6. The barcodedetection device as claimed in claim 2, wherein in calculating theaverage gradient vector, the processor is configured to recognizegradient vectors among the (N−1)×(N−1) gradient vectors directing to afirst direction and a second direction, change the gradient vectorsamong the (N−1)×(N−1) gradient vectors directing to the second directionto direct to the first direction, and average (N−1)×(N−1) gradientvectors directing to the first direction.
 7. The barcode detectiondevice as claimed in claim 2, wherein in calculating the averagegradient vector, the processor is configured to recognize gradientvectors among the (N−1)×(N−1) gradient vectors directing to a firstdirection and a second direction, and average the gradient vectors amongthe (N−1)×(N−1) gradient vectors directing only to the first directionor directing only to the second direction.
 8. The barcode detectiondevice as claimed in claim 2, wherein in calculating the averagegradient vector, the processor is configured to calculate an innerproduct or an angle difference of two gradient vectors among the(N−1)×(N−1) gradient vectors to determine whether the two gradientvectors direct to a same direction or not.
 9. The barcode detectiondevice as claimed in claim 1, wherein the barcode detection device isarranged on a character figure.
 10. The barcode detection device asclaimed in claim 9, further comprising a wireless interface configuredto be coupled to a game host.
 11. The barcode detection device asclaimed in claim 1, wherein the multiple bars have different colors ordifferent reflectivity.
 12. The barcode detection device as claimed inclaim 2, wherein the processor is further configured to identify avariation of the average gradient vector to determine whether thebarcode detection device is steady or not.
 13. A barcode detectiondevice, comprising: an image sensor, configured to capture an imageframe of a barcode, wherein the image frame has a size of N×N pixels,and the barcode has separately arranged multiple bars; and a processor,coupled to the image sensor, and configured to calculate a gradientdirection in the captured image frame, select a direction from fourpredetermined directions, which is closest to the gradient direction, ofthe captured image frame, and calibrate a scanned width of the multiplebars using an angle difference between the gradient direction and theselected direction.
 14. The barcode detection device as claimed in claim13, wherein the calibrated scanned width is calculated by the scannedwidth/sec (the angle difference).
 15. The barcode detection device asclaimed in claim 14, wherein the calibrated scanned width is configuredto indicate a real width of the multiple bars, a space of the barcode ora bar pitch of the barcode.
 16. The barcode detection device as claimedin claim 14, wherein the processor is further configured to compare thecalibrated width with a threshold to determine whether the barcodedetection device is lifted or not.
 17. The barcode detection device asclaimed in claim 14, wherein the processor is further configured tocompare the calibrated width with multiple thresholds to determine aheight of the barcode detection device with respect to the barcode. 18.The barcode detection device as claimed in claim 14, wherein theprocessor is further configured to identify a variation of the gradientdirection to determine whether the barcode detection device is steady ornot.
 19. The barcode detection device as claimed in claim 13, whereinthe processor is configured to calculate an average gradient vector of apredetermined number of gradient vectors of the predetermined number ofconvolution regions of the image frame as the gradient direction of themultiple bars.